package org.example.springboot3.controller;

import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.example.springboot3.common.Result;
import org.example.springboot3.entity.Employee;
import org.example.springboot3.service.EmployeeService;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    //浏览器新增json数据给后端
    @PostMapping("/add")
    public Result add(@RequestBody Employee employee) {
        employeeService.add(employee);
        return Result.success();
    }

    //删除单个数据
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        employeeService.deleteById(id);
        return Result.success();
    }
    //删除多个数据
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        employeeService.deleteBatch(ids);
        return Result.success();
    }

    //更新数据
    @PutMapping ("/update")
    public Result updata(@RequestBody Employee employee) {
        employeeService.updata(employee);
        return Result.success();
    }

    //查询所有数据
   @GetMapping("/selectALL")
    public Result selectAll(Employee employee){
       List<Employee> list = employeeService.selectALL(employee);
        return Result.success(list);
   }

   //路径传参@PathVariable 查询单个数据
   @GetMapping("/selectById/{id}")
   public Result selectById(@PathVariable Integer id) {
      Employee employee = employeeService.selectById(id);
       return Result.success(employee);
   }

   //分页查询
   @GetMapping("/selectPage")
    public Result selectPage(Employee employee,
            @RequestParam ( defaultValue = "1") Integer pageNum,
            @RequestParam (defaultValue = "10")Integer pageSize) {
       PageInfo<Employee> pageInfo = employeeService.selectPage(employee,pageNum,pageSize);
        return Result.success(pageInfo);
    }
    /**
     * 修改密码
     */
    @PutMapping("/updatePassword")
    public Result updatePassword(@RequestBody Employee employee) {
        employeeService.updatePassword(employee);
        return Result.success();
    }

}//

